<template>
  <el-container class="home-container">
    <!--头部区域-->
    <el-header>
      <div>
        <img src="../assets/toplogo.jpg" alt="">
        <span>焊接维护管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!--侧边栏 实现和数据同样宽度的折叠-->
      <el-aside :width="isCollapse?'64px':'200px'">
        <!--折叠菜单的按钮-->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!--侧边栏菜单区域-->
        <el-menu
          background-color="#0C7ED9"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          router="true"
          default-active="/users"
        >
          <!--一级菜单 item.id + ''用于转为字符串形式-->
          <el-submenu :index="item.id + ''" v-for="item in menuname" :key="item.id">
            <!-- 一级菜单模板区 -->
            <template slot="title">
              <!--<i :class="iconsObj[item.id]"></i>-->
              <!-- 文本 -->
              <span>{{item.name}}</span>
            </template>
            <!--二级菜单-->
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" >
              <span>{{subItem.name}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!--右边主题区域-->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    name: 'Home',
    data() {
      return {
        // 左侧菜单数据
        menulist: [],
        menuname:[
          {
            "id":1,
            "name": "生产线列表",
            "path": "line ",
            "children":[
              {
                "id":11,
                "name": "生产线列表1",
                "path": "firstline"
              },
              {
                "id":12,
                "name": "生产线列表2",
                "path": "line2"
              },
              {
                "id":13,
                "name": "生产线列表3",
                "path": "line3"
              },
            ]

          },
          {
            "id":2,
            "name": "历史数据查询列表",
            "path": "history",
            "children":[
              {
                "id":21,
                "name": "历史数据查询列表1",
                "path": "history1"
              },
              {
                "id":22,
                "name": "历史数据查询列表2",
                "path": "history2"
              }
            ]

          },
          {
            "id":3,
            "name": "异常管理",
            "path": "abnormal",
            "children":[
              {
                "id":31,
                "name": "异常管理查询列表1",
                "path": "abnormal1"
              },
            ]
          },
          {
            "id":4,
            "name": "账户管理",
            "path": "manage",
            "children":[]
          },
          {
            "id":5,
            "name": "软件设置",
            "path": "setting",
            "children":[]
          },
          // "生产线列表",
          // "历史数据查询列表",
          // "异常管理",
          // "账户管理",
          // "软件设置",
        ],
        menuname1:[
          "aaa",
          "vvv",
          "bbb",
        ],
        //不同图标的数组
        iconsObj: {
          '125': 'el-icon-user-solid',
          '103': 'el-icon-s-check',
          '101': 'el-icon-s-shop',
          '102': 'el-icon-s-order',
          '145': 'el-icon-s-marketing'
        },
        // 是否折叠
        isCollapse: false,
        // 被激活的链接地址
        activePath: ''
      }


    },
    //钩子函数，当进入到此页面时候自动触发,获取侧边栏的数据然后自动填入
    created() {
      // console.log()
    },
    methods:{
      logout(){
        // 调用库函数，清理会话存储中的值
        window.sessionStorage.clear();
        this.$router.push('/login');
      },
      // 点击按钮，切换菜单的折叠与展开
      toggleCollapse(){
        this.isCollapse = !this.isCollapse;
      },
    }
  }
</script>

<style lang="less" scoped>
  .home-container{
    height:100%;
  }
  .el-menu{
    border-right: none;
  }
  .el-main{
    background-color:#FFFFFF;
  }
  .el-aside{
    background-color:#F5F7FA;
  }
  .el-header{
    background-color:#0C7ED9;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;
    >div{
    display: flex;
    align-items: center;
      span {
        margin-left: 15px;
      }
    }
  }
  /*.div1{*/
    /*display: flex;*/
    /*align-items: center;*/
  /*}*/
  .span1{
    margin-left: 15px;
  }
  .toggle-button {
    background-color: #0C7ED9;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
